<template>
  <div class="Source">
    <div class="top">
      <div class="title">货源信息</div>
    </div>
    <div class="main">
      <div class="filter">
        <div class="title">货源信息筛选</div>
        <div class="area">
          <!-- 发货地 -->
          <div class="item" v-if="false">
            <div class="left">
              <div class="t1">发货地 :</div>
            </div>
            <div class="right">
              <div :class="{city:true,active:!filterdata.city}" @click="selectEvt('city','')">不限</div>
              <div
                v-for="(item,index) in citys"
                :key="index"
                :class="{city:true,active:filterdata.city == item}"
                @click="selectEvt('city',item)"
              >{{ item }}</div>
            </div>
          </div>

          <!-- 线路筛选 -->
          <div class="item">
            <div class="left">
              <div class="t1">线路筛选 :</div>
            </div>
            <div class="right line">
              <el-cascader
                placeholder="发货地"
                :props="{ checkStrictly: true,value:'label' }"
                :options="areaList"
                filterable
                @change="(e)=>handleChange(e,'ship')"
              ></el-cascader>
              <span class="space">至</span>
              <el-cascader
                placeholder="卸货地"
                :props="{ checkStrictly: true,value:'label' }"
                :options="areaList"
                filterable
                @change="(e)=>handleChange(e,'to')"
              ></el-cascader>
              <el-button type="primary" class="searchBtn" @click="search">搜索</el-button>
            </div>
          </div>

          <!-- 车型 -->
          <div class="item">
            <div class="left">
              <div class="t1">车型 :</div>
            </div>
            <div class="right">
              <div :class="{city:true,active:!filterdata.models}" @click="selectEvt('models','')">不限</div>
              <div
                v-for="(item,index) in carTypes"
                :key="index"
                :class="{city:true,active:filterdata.models == item}"
                @click="selectEvt('models',item)"
              >{{ item }}</div>
            </div>
          </div>
        </div>
      </div>
      <div class="list">
        <div class="tips" v-if="sourceList.length == 0"> 
          <img src="@/assets/icon/nodata.png" alt="">
          暂无数据</div>
        <SourceCard v-for="(item,index) in sourceList" :key="index" :sourceInfo="item" />
      </div>
      <div class="pagination">
        <el-pagination
          v-if="sourceList.length != 0"
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-sizes="[10, 15, 20, 25]"
          :page-size="pageSize"
          layout="total,sizes, prev, pager, next"
          :total="total"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import SourceCard from "./components/SourceCard";
import { areaList } from "@/utils/citys";
import { getSourceGoodsList } from "@/api/configApi.js";
export default {
  name: "Source",
  components: {
    SourceCard
  },
  data() {
    return {
      sourceList: [],
      currentPage: 1,
      pageSize: 10,
      total: 0,
      filterdata: {
        ship_address: "",
        to_address: "",
        models: ""
      },
      carTypes: ["平板", "高栏", "箱式", "半挂"],
      areaList
    };
  },
  mounted() {
    this.initial();
  },
  methods: {
    async initial() {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      let result = await getSourceGoodsList({
        pageSize: this.pageSize,
        page: this.currentPage,
        ...this.filterdata
      });
      if (result.code == 200) {
        this.total = result.total;
        this.sourceList = result.data;
      }
      document.documentElement.scrollTop = 0;
      loading.close();
    },
    selectEvt(type, val) {
      this.filterdata[type] = val;
      this.initial();
    },
    handleChange(e, type) {
      if (type == "ship") {
        this.filterdata.ship_address = e.join("-");
      }
      if (type == "to") {
        this.filterdata.to_address = e.join("-");
      }
    },
    search() {
      this.initial();
    },
    handleCurrentChange() {
      this.initial();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.initial();
    }
  }
};
</script>

<style lang="scss" scoped>
.Source {
  background: #f3f3f3;
  min-height: 100vh;
  .el-cascader {
    width: 300px;
  }
  .top {
    height: 200px;
    background: $primaryColor;
    text-align: center;
    .title {
      padding-top: 100px;
      margin-bottom: 16px;
      font-family: Open Sans;
      font-weight: 300;
      font-size: 3.375em;
      line-height: 1.26;
      color: rgb(255, 255, 255);
    }
  }
  .main {
    width: 60vw;
    margin: 0 auto;
    padding-bottom: 30px;
    // background: pink;
    .filter {
      .title {
        font-size: 18px;
        font-weight: 700;
        color: #333;
        padding: 20px 0;
      }
      .area {
        min-height: 100px;
        background: #fff;
        border-radius: 10px;
        padding: 10px;
        padding-top: 20px;
        box-sizing: border-box;
        .item {
          display: flex;
          margin-bottom: 20px;
          .left {
            width: 10%;

            .t1 {
              padding: 10px 20px;
              font-weight: 500;
              font-size: 15px;
              color: #999;
              box-sizing: border-box;
            }
          }
          .right {
            flex: 1;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            .searchBtn {
              margin-left: 20px;
              background: $primaryColor;
            }
            .space {
              margin: 0 15px;
            }

            .city {
              box-sizing: border-box;
              padding: 5px 10px;
              font-size: 15px;
              margin-top: 5px;
              display: flex;
              margin-right: 15px;
              margin-bottom: 10px;
              &:hover {
                cursor: pointer;
                color: $primaryColor;
              }
            }
            .active {
              background: $primaryColor;
              color: #fff;
              border-radius: 15px;
              &:hover {
                cursor: pointer;
                color: #fff;
              }
            }
          }
        }
      }
    }
    .list {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      .tips {
        height: 400px;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        color: #999;
        flex-direction: column;
        font-weight: bold;
        img {
          width: 50px;
          margin-bottom: 5px;
        }
      }
    }
  }
  .pagination {
    display: flex;
    justify-content: center;
    margin-top: 10px;
    width: 100%;
    overflow: hidden;
  }
  @media screen and (max-width: 767px) {
    .main {
      width: 90vw;
      .filter {
        .area {
          .item {
            flex-direction: column;
            .left {
              width: 35%;
            }
            .line {
              flex-direction: column;
              align-items: flex-start;
            }
            .right {
              margin-left: 20px;
              .space {
                margin: 10px 0;
              }
              .searchBtn {
                margin-top: 10px;
                margin-left: 0;
              }
            }
          }
        }
      }
    }
  }
}
</style>
